user_key="6CSBYCF2K94K9UCA"
secret_key="GNA2A6TTFV7WX9MDBM9F2PBJS9WUAUVZ"
key_url="http://api.cssummer.top/index.php?key=$user_key"
echo "--- Installing screen ---"
if type screen 2>/dev/null; then  
    echo "screen is installed and hashed."  
else  
    echo "-->Screen is not hashed, installing..."  
    yum install screen -y
fi
echo "-------------  Installing wget  --------------"
echo "-------------   Checking wget   --------------"
if type wget >/dev/null 2>&1; then  
    echo "---> wget is installed."  
else  
    echo "---> wget is not installed."  
    yum install wget -y
fi
wget -O "1.txt" "$key_url"
onlineKey=$(cat "1.txt" | tr -d '\t\n\r')
if [ "$onlineKey" = "$secret_key" ]; then
    echo "--- Key Verify Correct. ---"
    rm 1.txt -rf
else
    echo "Key incorrect"
    rm 1.txt -rf
    exit
fi
echo "Bash Script: Install TS3 Server"
ts_bsversion="1.1.0"
echo "Your Version is $ts_bsversion"
echo "----- Checking For Update -----"
sleep 3
wget "https://gitee.com/g2summer/software-problem-feedback/raw/master/ts3.html"
html_file="ts3.html"
version=$(cat "$html_file" | tr -d '\t\n\r')
if [ "$ts_bsversion" = "$version" ]; then
    echo "This Script File is the latest. Version: $version"
    rm ts3.html -rf
else
    echo "This Script File is not the latest Version: $ts_bsversion, the latest version is: $version"
    echo "The Shell Will Exit in 10s, you can Visit https://gitee.com/g2summer/install_ts3sv for the Latest version"
    rm ts3.html -rf
    sleep 10s
    exit
fi

echo "---Install Teamspeak3 Server | Linux (This script is made by Summer.)---"
sleep 2
echo "-----Firewall Operations-----"
echo ""
sleep 2
echo "---This Script is Made for TeamSpeak3 Server V=3.13.7_amd64---"
echo ""
sleep 1
echo "---Now Creating Rules For Port:9987-udp (Default Voice Service)---"
firewall-cmd --zone=public --add-port=9987/udp --permanent #放行9987端口
echo ""
sleep 1
echo "---Now Creating Rules For Port:10011-tcp (ServerQuery raw Port)---"
firewall-cmd --zone=public --add-port=10011/tcp --permanent #放行10011端口
echo ""
sleep 1
echo "---Now Creating Rules For Port:10022-tcp (ServerQuery SSH Port)---"
firewall-cmd --zone=public --add-port=10022/tcp --permanent #放行10011端口
echo ""
sleep 1
echo "---Now Creating Rules For Port:30033-tcp (FTP Port)---"
firewall-cmd --zone=public --add-port=30033/tcp --permanent #放行9987端口
echo ""
sleep 1
echo "---Now Creating Rules For Port:41144-tcp (TSDNS Port)---"
firewall-cmd --zone=public --add-port=41144/tcp --permanent #放行10011端口
echo ""
sleep 1
echo "----- Firewall Opreations Complete! -----"
echo "--  Clear the Screen after 5 Seconds!  --"
sleep 5
clear
echo "--------Downloading Files From Internet-------"
sleep 2
echo "--  Clear the Screen after 2 Seconds!  --"
sleep 2
clear
wget "ts3.tar.bz2" "https://downloads.cssummer.top/ts3.tar.bz2"
echo "---- Unziping... ----"
tar -xjvf "ts3.tar.bz2"
echo "---Deleting Trash Files---"
rm "ts3.tar.bz2" -rf
cd teamspeak3-server_linux_amd64
echo "--- Creating Lincense File! ---"
touch .ts3server_license_accepted
echo "license_accepted=1" > .ts3server_license_accepted
sleep 3
echo "--- Server Installed! Now Starting...(test for start) ---"
sh ./ts3server_startscript.sh start
